﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LanguageTraning
{

    // Declare a delegate
    delegate void Printer(string s);
    delegate void MyPrinter();
    class AnonymousMethod
    {
        public void TestMethod()
        {
            Console.WriteLine("---------------------------------------------");
            Console.WriteLine("this is example of {0}", this.GetType().ToString());

            Printer p = null;
            // The delegate instantiation using a named method "DoWork":
            p = new Printer(DoWork);
            // Results from the old style delegate call:
            p("The delegate using the named method is called.");

            // Instatiate the delegate type using an anonymous method:
            p = delegate(string j)
            {
                System.Console.WriteLine(j);
            };
            // Results from the anonymous delegate call:
            p("The delegate using the anonymous method is called.");

            

            // The delegate instantiation using a lamba:
            p = (j) => { Console.WriteLine(j); };
            // Results from the old style delegate call:
            p("The delegate using Lamba is called.");

            MyPrinter mp = () => Console.WriteLine();
        }

        // The method associated with the named delegate:
        public static void DoWork(string k)
        {
            System.Console.WriteLine(k);
        }

        public static int DoWork(int input)
        {
            return input;
        }
    }
    
}
